//
// Created by Administrator on 2024/11/1.
//


#include "RequestJson.h"


bool Request::read(struct mg_connection * conn) {
    auto *ri = const_cast<mg_request_info *>(mg_get_request_info(conn));
    auto content_length = ri->content_length;

    std::string buf(content_length, '\0');
    auto received = mg_read(conn, &buf[0], content_length);
    if (received > 0) {
        j_complete = json::parse(buf);
        return true;
    }
    return false;
}

void Request::print() const {
    std::cout << std::setw(4) << j_complete << "\n\n";
}

json Request::getData() const {
    return j_complete;
}
